<template>
  <div>
    <Card>
      <tables ref="tables" editable searchable search-place="top" v-model="tableData" :columns="columns"
        @on-delete="handleDelete" />
      <Button style="margin: 10px 0;" type="primary" @click="exportExcel">导出为excel文件</Button>
    </Card>
  </div>
</template>

<script>
import Mock from 'mockjs'
import Tables from '_c/tables'
import {
  machineGroupNameValues,
  machineNumberValues,
} from '@/mock/data/option-data.js'
import rcRequest from 'rc-request'
import jsCookie from 'js-cookie'

export default {
  name: 'discount_code_statis_page',
  components: {
    Tables
  },
  data() {
    return {
      columns: [
        { title: '机器组名', key: 'machineGroupName' },
        { title: '机器编号', key: 'machineNum' },
        { title: '机器名', key: 'machineName', width: 120 },
        { title: '机器温度(°C)', key: 'temperation' },
        { title: '开始日期', key: 'startDate' },
        { title: '结束日期', key: 'endDate' },
        // {
        //   title: '操作',
        //   key: 'action',
        //   width: 150,
        //   render: (h, params) => {
        //     return h('div', [
        //       h('Button', {
        //         props: {
        //           type: 'warning',
        //           size: 'small',
        //           ghost: true,
        //         },
        //         on: {
        //           click: () => this.tableData.splice(params.index, 1)
        //         },
        //       }, '删除'),
        //     ]);
        //   }
        // }
      ],
      tableData: [],
    }
  },
  methods: {
    handleDelete(params) {
      console.log(params)
    },
    exportExcel() {
      this.$refs.tables.exportCsv({
        filename: `机器温度查询-${(new Date()).valueOf()}.csv`
      })
    },
    // 获取列表数据
    async getListData() {
      const { data: { data } } = await rcRequest({
        method: 'post',
        url: '/machine/select_machine_temperature',
        data: { }
      })
      this.tableData = data.map(item => ({
        id: `${item.id}`,
        machineGroupName: item.machine_group_name,
        machineNum: item.number,
        machineName: item.name,
        temperation: item.temperature,
        startDate: item.create_time,
        endDate: item.expire_time,
      }))
    },
  },
  mounted() {
    this.getListData()
  }
}
</script>

<style scoped>

</style>
